import request from '@/utils/request.js'

export const getKnowledgeCategories = () => {
	const params = { page: 1, limit: 10000 }
	return request({
		url: '/sort/search',
		method: 'get',
		params
	})
}

export const httpKnowledgeList = (params) => {
	return request({
		url: '/knowledge/search',
		method: 'get',
		params
	})
}

export const httpKnowledgeCollects = () => {
	return request({
		url: '/knowledge/collects',
		method: 'get'
	})
}

export const httpCollectKnowledge = (knowledge_id) => {
	const params = { knowledge_id }
	return request({
		url: '/knowledge/collect',
		method: 'get',
		params
	})
}

export const httpFiles = (params) => {
	return request({
		url: '/knowledge/file-list',
		method: 'get',
		params
	})
}



export const httpSave = (data) => {
	return request({
		url: `/knowledge/${data.knowledge_id ? 'update-info' : 'create'}`,
		method: 'post',
		data
	})
}

export const httpDelete = (id) => {
	const data = { knowledge_id: id }
	return request({
		url: `/knowledge/delete`,
		method: 'post',
		data
	})
}


export const httpUploadFiles = (formData) => {
	return request({
		url: '/knowledge/upload-docs',
		method: 'post',
		transformRequest: [function() {
			return formData
		}]
	})
}

export const httpDeleteFiles = (data) => {
	return request({
		url: '/knowledge/delete-docs',
		method: 'post',
		data
	})
}

export const updateUseTimes = (knowledge_id) => {
	const data = { knowledge_id }
	return request({
		url: '/knowledge/click',
		method: 'post',
		data
	})
}

export const getKnowledgeInfo = (knowledge_id) => {
	const params = { knowledge_id }
	return request({
		url: '/knowledge/name',
		method: 'get',
		params
	})
}